package com.taobao.top
{
	import com.adobe.serialization.json.JSON;
	public class TOPError
	{
		public function TOPError()
		{
		}
		private var code:int;
		private var msg:String;
		private var chnMsg:String;
		
		public function set Code(value:int):void
		{
			this.code = value;
		}
		
		public function get Code():int
		{
			return code;
		}
		
		public function set Msg(value:String):void
		{
			msg = value;
		}
		
		public function get Msg():String
		{
			return msg;
		}
		
		public function get ChnMsg():String
		{
			return chnMsg;	
		}
		
		public function set ChnMsg(value:String):void
		{
			chnMsg = value;
		}
		
		public static function isError(jsonStr:String):Boolean
		{
			return jsonStr.indexOf("{\"error_rsp\"") == 0;
		}
		
		public static function parseError(errorJson:String):TOPError
		{
			var topError:TOPError = new TOPError();
			var obj:Object = JSON.decode(errorJson);
			topError.Msg = obj.error_rsp.msg;
			topError.Code = obj.error_rsp.code;
			
			switch(obj.error_rsp.code)
			{
				case 3:
					topError.ChnMsg = "上传附件失败";
				break;
				case 5:
					topError.ChnMsg = "用户会话期呼叫频度受限";
				break;
				case 9:
					topError.ChnMsg = "该方法不允许使用此Http动作";
				break;
				case 10:
					topError.ChnMsg = "服务不可用";
				break;
				case 11:
					topError.ChnMsg = "第三方程序权限不够";
				break;
				case 12:
					topError.ChnMsg = "用户权限不够";
				break;
				case 21:
					topError.ChnMsg = "方法丢失";
				break;
				case 22:
					topError.ChnMsg = "方法无效";
				break;
				case 23:
					topError.ChnMsg = "响应格式无效";
				break;
				case 24:
					topError.ChnMsg = "签名丢失";
				break;
				case 25:
					topError.ChnMsg = "签名无效";
				break;
				case 26:
					topError.ChnMsg = "会话期识别码丢失";
				break;
				case 27:
					topError.ChnMsg = "会话期识别码无效";
				break;
				case 28:
					topError.ChnMsg = "App_Key丢失";
				break;
				case 29:
					topError.ChnMsg = "App_Key无效";
				break;
				case 30:
					topError.ChnMsg = "时间戳丢失";
				break;
				case 31:
					topError.ChnMsg = "时间戳无效";
				break;
				case 32:
					topError.ChnMsg = "版本丢失";
				break;
				case 33:
					topError.ChnMsg = "版本错误";
				break;
				case 40:
					topError.ChnMsg = "参数丢失，指除 method ,session ,timestamp ,format ,app_key ,v ,sign外的其他参数丢失";
				break;
				case 41:
					topError.ChnMsg = "参数格式错误";
				break;
				case 550:
					topError.ChnMsg = "用户数据服务不可用";
				break;
				case 551:
					topError.ChnMsg = "商品数据服务不可用";
				break;
				case 552:
					topError.ChnMsg = "商品图片数据服务不可用";
				break;
				case 553:
					topError.ChnMsg = "上下架，推荐，取消推荐 服务不可用";
				break;
				case 560:
					topError.ChnMsg = "交易数据服务不可用";
				break;
				case 590:
					topError.ChnMsg = "店铺服务不可用";
				break;
				case 591:
					topError.ChnMsg = "店铺剩余推荐数 服务不可用";
				break;
				case 601:
					topError.ChnMsg = "用户不存在";
				break;
			}
			return topError;
		}
	}
}